package com.itheima.array;

import java.util.Arrays;

public class MaoPao {

    public static void main(String[] args) {
        int[] arr={88,66,99,55,44,11};

      /*  //5轮 比较
        //第一轮 比较5次
        for (int i = 0; i < arr.length-1; i++) {
            //arr[i] arr[i+1]
            if(arr[i]>arr[i+1]){
                int temp=arr[i];
                arr[i]=arr[i+1];
                arr[i+1]=temp;
            }
        }
        System.out.println(Arrays.toString(arr));
        //第二轮 比较4 次
        for (int i = 0; i < arr.length-1-1; i++) {
            if(arr[i]>arr[i+1]){
                int temp=arr[i];
                arr[i]=arr[i+1];
                arr[i+1]=temp;
            }
        }
        System.out.println(Arrays.toString(arr));
//第3轮 比较3 次
        for (int i = 0; i < arr.length-1-1-1; i++) {
            if(arr[i]>arr[i+1]){
                int temp=arr[i];
                arr[i]=arr[i+1];
                arr[i+1]=temp;
            }
        }
        System.out.println(Arrays.toString(arr));
        //第4轮 比较2 次
        for (int i = 0; i < arr.length-1-1-1-1; i++) {
            if(arr[i]>arr[i+1]){
                int temp=arr[i];
                arr[i]=arr[i+1];
                arr[i+1]=temp;
            }
        }
        System.out.println(Arrays.toString(arr));
        //第5轮 比较1 次
        for (int i = 0; i < arr.length-1-1-1-1-1; i++) {
            if(arr[i]>arr[i+1]){
                int temp=arr[i];
                arr[i]=arr[i+1];
                arr[i+1]=temp;
            }
        }
        System.out.println(Arrays.toString(arr));*/

        冒泡排序(arr);

        System.out.println(Arrays.toString(arr));
    }

    public static void 冒泡排序(int[] arr) {
        //轮次
        int temp=0;
        for (int i = 0; i < arr.length - 1; i++) {
            //比较的次数
            for (int j = 0; j < arr.length - 1-i; j++) {
                //符合交换条件猜交换
                if (arr[j]>arr[j+1]) {
                    temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }

            }
        }
    }
}
